﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class city : System.Web.UI.MasterPage
{

    protected void Page_Init(object sender, EventArgs e)
    {
        ctp_lib.check_user_language(this.Page);
    }

    public string ct_name = "";


    protected void Page_Load(object sender, EventArgs e)
    {
        //init helper class
        GeoLingManager glManager = new GeoLingManager(Request, Response);
        String _lang = glManager.getLang();
        DatabaseUtil dbUtil = new DatabaseUtil();
        //Get user's preferred langugage in int
        _lang = dbUtil.getLanguageNo(_lang).ToString();
        int no = int.Parse(Request["no"]);

        if (!this.IsPostBack)
        {
            System.IO.FileInfo fn = new System.IO.FileInfo(this.Page.MapPath(this.Page.Request.Path));
            

            //Response.Write(fn.Name);

            ctpDataContext db = new ctpDataContext();
            ct_profile ct = db.ct_profiles.Single(p => p.no == no && p.language_no == (int)Session["now_user_lang_no"]);


            //if (fn.Name != "city.aspx")
            //{
            //    this.HyperLink7.NavigateUrl = "city.aspx?no=" + no;
            //    this.HyperLink8.NavigateUrl = "city.aspx?no=" + no;
            //    this.HyperLink8.Text = ct.title.Trim().ToUpper() ;
            //}
            //else
            //{
                //this.HyperLink8.Visible = false;
            //}


            this.HyperLink6.NavigateUrl = "create_city_s.aspx?no=" + no;

            this.HyperLink11.NavigateUrl = "city_travel.aspx?no=" + no;
            this.HyperLink12.NavigateUrl="city_local.aspx?no="+no;



            //this.Label1.Text = ct.title;
            String title = dbUtil.getPropertyPost(ct.title.Trim(), (int)DatabaseUtil.fromTables.ct_profile_title, ct.no, _lang);
            this.HyperLink7.Text = title;
            ct_name=title.ToUpper();

            // this.HyperLink2.NavigateUrl = "create_city_s.aspx?no=" + no;
            this.Label3.Text = ct.country.Trim();


            if (ct.main_pic_fn != null)
            {
                this.Image3.ImageUrl = "city_imgs/2/" + ct.main_pic_fn.Trim();
            }
            else
            {
                this.Image3.Visible = false;
            }


            user manager = null;
            if (ct.manager_user_no == null)
            {
                this.HyperLink5.Text = ct.user.nickname.Trim();
                this.HyperLink5.NavigateUrl = "user_profile.aspx?no=" + ct.create_user_no.ToString();
            }
            else
            {
                 manager = db.users.Single(p => p.no == ct.manager_user_no);

                this.HyperLink5.Text = manager.nickname.Trim();
                this.HyperLink5.NavigateUrl = "user_profile.aspx?no=" + ct.manager_user_no.ToString();
                this.Label5.Text = "Managed";

            }

            int continent = (int)ct.continent;
            switch (continent)
            {
                case 0:
                    this.Label4.Text = "Asia";
                    break;
                case 1:
                    this.Label4.Text = "America";
                    break;
                case 2:
                    this.Label4.Text = "Africa";
                    break;
                case 3:
                    this.Label4.Text = "Europe";
                    break;
                case 4:
                    this.Label4.Text = "Oceania";
                    break;
            }


            if (manager!= null)
            {
                if (manager.profile_picture != null)
                {
                    this.Image2.ImageUrl = "user_imgs/1/" + manager.profile_picture.Trim();
                }
                else
                {
                    this.Image2.Visible = false;
                }
            }
            else if (ct.user.profile_picture != null)
            {

                this.Image2.ImageUrl = "user_imgs/1/" + ct.user.profile_picture.Trim();
            }
            else
            {
                this.Image2.Visible = false;
            }


            this.HyperLink9.NavigateUrl = "city.aspx?no=" + no.ToString();
            this.HyperLink10.NavigateUrl = "city_best.aspx?no=" + no.ToString();
            



        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Response.Redirect("search.aspx?text="+this.TextBox1.Text);
    }
}
